<template>
  <van-icon
    @click="lodagetCollections"
    :color="value ? 'red' : '#777'"
    :name="value ? 'like' : 'like-o'"
    :loading="loading"
  />
</template>

<script>
import { getCollections, deleteCollections } from '@/api/article'
export default {
  name: 'CollectArticle',
  props: {
    value: {
      type: Boolean,
      require: true
    },
    ArticleId: {
      type: [Number, String, Object],
      require: true
    }
  },
  data () {
    return {
      loading: false
    }
  },
  methods: {
    async lodagetCollections () {
      this.loading = true
      try {
        if (this.value) {
          await deleteCollections(this.ArticleId)
        } else {
          await getCollections(this.ArticleId)
        }
        this.$emit('input', !this.value)
        this.$toast.success(!this.value ? '收藏成功' : '取消收藏')
      } catch (err) {
        this.$toast.fail('收藏失败')
      }
      this.loading = false
    }
  }
}
</script>
<style lang="less" scope>
</style>
